package com.lc202309;

import java.util.HashMap;
import java.util.Map;

/**
 * Description:
 *
 * @Create 2023/9/2 23:18
 * @Version 1.0
 */
public class Solution169 {
    public int majorityElement(int[] nums) {
        Map<Integer, Integer> map = new HashMap<>();
        int length = (nums.length + 1) / 2;
        for (int num : nums) {
            int size = map.getOrDefault(num, 0) + 1;
            if (size >= length) {
                return num;
            }
            map.put(num,size);
        }
        return 0;
    }
}
